<template>
  <!-- 成交管理=== 合同列表 -->
  <el-dialog
    title="合同列表"
    v-model="visible"
    width="50%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-table :data="list" style="width: 100%" border>
      <el-table-column
        label="ID"
        prop="id"
        width="60"
        fixed
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="合同编号"
        prop="num"
        min-width="50"
        fixed
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column label="合同类型" prop="typeName" width="100">
      </el-table-column>
      <el-table-column label="合同金额" prop="money" width="150">
        <template #default="scope">
          <p v-if="scope.row.refundMoney == 0">
            {{ scope.row.money }}元
            <span v-if="scope.row.isIncludeTax == 1"
              >(含税{{ scope.row.taxRate == 1 ? 6 : 13 }}%)</span
            >
          </p>
          <p v-if="scope.row.refundMoney != 0">
            {{ scope.row.money }}元(已退款{{ scope.row.refundMoney }}元
            <span v-if="scope.row.isIncludeTax == 1"
              >含税{{ scope.row.taxRate == 1 ? 6 : 13 }}%</span
            >)
          </p>
        </template>
      </el-table-column>
      <el-table-column label="收款方式" width="150">
        <template #default="scope">
          <p v-if="scope.row.paymentMethod == 1">
            预付款 +
            {{ scope.row.combination == 2 ? "到付" : "约定时间" }}
          </p>
          <p v-if="scope.row.paymentMethod == 2">到付</p>
          <p v-if="scope.row.paymentMethod == 3">约定时间</p>
        </template>
      </el-table-column>
      <el-table-column label="签订时间" prop="orderTime" width="120">
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="currentPage"
      small
      layout="total, prev, pager, next"
      :page-size="limit"
      :total="total"
      @current-change="handleCurrentChange"
      v-if="total > 10"
    />
  </el-dialog>
</template>

<script>
import { queryTypeByDic } from "@/utils/getData"
export default {
  emits: ['success', 'closed'],
  data () {
    return {
      visible: false,
      list: [],
      customerId: '',
      limit: 10,//每页条数
      page: 1,//页码
      currentPage: 1,
      pageSize: 1,
      total: 0

    }
  },

  mounted () {

  },
  methods: {
    //显示
    open (data) {
      this.visible = true
      this.customerId = data.id
      this.getList(data.id)
    },
    async getList () {
      let params = { customerId: this.customerId, page: this.page, limit: this.limit }
      let res = await this.$API.contract.dealManagement.getContractList.get(params)
      if (res.code == 200) {
        this.list = res.data
        this.total = res.total
        queryTypeByDic("contractType").then((res) => {
          this.list.forEach((item) => {
            res.forEach((t_item) => {
              if (item.type == t_item.value) {
                item.typeName = t_item.name
              }
            })
          })
        })
      }
    },

    handleCurrentChange (val) {
      this.page = val
      this.getList()
    }



  }
}
</script>

<style lang='scss' scoped>
</style>
